<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="s" uri="http://shiro.apache.org/tags"%>
<%@ include file="/WEB-INF/view/include/inc.jsp"%>
<!DOCTYPE html>
<html>
<head>
<%@ include file="/WEB-INF/view/include/jQgrid.jsp"%>

<link type="text/css" rel="stylesheet"
	href="<%=contextPath %>/plugins/zTree/2.6/zTreeStyle.css" />
<script type="text/javascript"
	src="<%=contextPath %>/plugins/zTree/2.6/jquery.ztree-2.6.min.js"></script>
</head>
<body>
	<div class="">
		<div class="row">
			<div class="col-sm-12">
				<div class="ibox " style="margin-bottom: 0px;">
					<div class="ibox-title" style="border-color: white;">
						<div class="row">
							<div class="col-sm-3">
								<div class="input-group">
									<input id="uname" type="text" placeholder="请输入关键词"
										class="input-sm form-control"> <span
										class="input-group-btn"> <a id="find_btn" type="button"
										class="btn btn-sm btn-primary"> 搜索</a>
									</span>
								</div>
							</div>
							<s:hasPermission name="area:add">
								<div class="col-sm-3">
									<a id="add_btn" type="button" class="btn btn-sm btn-success"
										onclick="add()">新增</a> </span>
								</div>
							</s:hasPermission>
						</div>
					</div>
					<div class="ibox-content">

						<div class="jqGrid_wrapper">
							<table id="table_list"></table>
							<div id="pager_list"></div>
						</div>

					</div>
				</div>
			</div>
		</div>
	</div>
	<!-- Page-Level Scripts -->
	<script>
		$(document).ready(function() {
			$.jgrid.defaults.styleUI = "Bootstrap";
			$("#table_list").jqGrid({
				url: '<%=contextPath %>/area/getAreaBypid',
				data : {},
				datatype : "json",
				autowidth : true,
				shrinkToFit : true,
				mtype : "post",
				rowNum : 20,
				rowList : [ 10, 20, 30 ],
				colNames : ["id", "区域名称","操作"],
				colModel : [{
					name : "id",
					index : "id",
					hidden:true
				},  {
					name : "area.title",
					index : "area.title",
					width : 100
				},{
					formatter:function(cellvalue, options, row){
						if(row.level==1){
					     return  "<s:hasPermission name="area:add"><a class='btn btn-mini btn-success' title='添加市州' onclick='addarea1("+row.id+")'><i class='icon-plus'>添加市州</i></a></s:hasPermission>"
					     +"<s:hasPermission name="area:detail"><a class='btn btn-small btn-info' title='查看' onclick='showdetail("+row.id+")'><i class='icon-eye-open'></i></a></s:hasPermission> "
					         +" <s:hasPermission name="area:update"><a class='btn btn-mini btn-warning' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a></s:hasPermission> "
							   +" <s:hasPermission name="area:delete"><a class='btn btn-mini btn-danger' title='删除' onclick='del("+row.id+")'><i class='icon-trash'></i></a></s:hasPermission> ";
						}else if(row.level==2){
							return  "<s:hasPermission name="area:add"><a class='btn btn-mini btn-success' title='添加区县' onclick='addarea2("+row.id+")'><i class='icon-plus'>添加区县</i></a></s:hasPermission>"
						     +"<s:hasPermission name="area:detail"><a class='btn btn-small btn-info' title='查看' onclick='showdetail("+row.id+")'><i class='icon-eye-open'></i></a></s:hasPermission> "
						         +" <s:hasPermission name="area:update"><a class='btn btn-mini btn-warning' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a></s:hasPermission> "
								   +" <s:hasPermission name="area:delete"><a class='btn btn-mini btn-danger' title='删除' onclick='del("+row.id+")'><i class='icon-trash'></i></a></s:hasPermission> ";
						}else{
							return  "<s:hasPermission name="area:detail"><a class='btn btn-small btn-info' title='查看' onclick='showdetail("+row.id+")'><i class='icon-eye-open'></i></a></s:hasPermission> "
						         +" <s:hasPermission name="area:update"><a class='btn btn-mini btn-warning' title='修改' onclick='showedit("+row.id+")'><i class='icon-edit'></i></a></s:hasPermission> "
								   +" <s:hasPermission name="area:delete"><a class='btn btn-mini btn-danger' title='删除' onclick='del("+row.id+")'><i class='icon-trash'></i></a></s:hasPermission> ";
						}
						},
					width : 150
				}],
				 treeReader : {  
					 level_field: "level",  
				      parent_id_field: "parent",   
				      leaf_field: "leaf",  
				      expanded_field: "expanded"  
				    },  
			    jsonReader: {      
			        root: "rows",    
			        repeatitems : false      
			      },   
				ExpandColumn: "area.title",
				treeGrid: true,
				height : $(window).height() - 130,
				treeGridModel: "adjacency"
			});
			
			//表格自适应高宽
			$(window).bind("resize", function() {
				var b = $(".jqGrid_wrapper").width();
				$("#table_list").setGridWidth(b);
				$("#table_list").setGridHeight($(window).height() - 170);
			})
			
			$("#table_list")
			.navGrid('#pager_list',{edit:false,add:false,del:false,search:false})
			$("#find_btn").click(function(){ 
		        var uname = $("#uname").val(); 
		        $("#table_list").jqGrid('setGridParam',{ 
		            postData:{'areaName':uname}, //发送数据 
		            page:1 
		        }).trigger("reloadGrid"); //重新载入 
		    }); 
			
		});
		function showdetail(id){
			 openyem("查看区域","<%=contextPath %>/area/detailView?id="+id,550,850);//查看页面
		}
		function add(){
			 openyem("添加区域","<%=contextPath %>/area/addView?level=1",550,850);//打开页面
		}
		function addarea1(id){
			 openyem("添加市州","<%=contextPath %>/area/addView?fatherId="+id+"&level=2",400,389);//打开页面
		}
		function addarea2(id){
			 openyem("添加区县","<%=contextPath %>/area/addView?fatherId="+id+"&level=3",400,389);//打开页面
		}
		//删除
		function del(id){
			swalopen(id,"<%=contextPath %>/area/delete");
		};
		
		//修改
		function showedit(id){
			openyem("修改区域","<%=contextPath %>/area/editView?id=" + id, 550, 850);
		}
	</script>

</body>
</html>

